package tian.weepmoon.multithreading.threadpool;

import java.util.concurrent.*;

/**
 * @author duyutian
 * @version 1.0
 * @date 2020/6/24 10:37
 * 当线程池使用的是静默DiscardPolicy 拒绝的处理的策略
 * 会出现submit无限等待的问题。
 */
public class FutureWaitExcept {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 2, 60,
                TimeUnit.SECONDS, new LinkedBlockingQueue<>(10), new ThreadPoolExecutor.DiscardPolicy());
        Future<?> submit = null;
        for (int i = 0; i < 20; i++) {
            System.out.println(i);
            submit = threadPoolExecutor.submit(() -> {
                try {
                    Thread.sleep(2000);
                    System.out.println("执行了");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }
        submit.get();
    }
}
